//
//  String+Reg.swift
//  yiplayer
//
//  Created by cgw on 2024/5/10.
//

import Foundation

extension String{
    // 替换掉所有的反斜杠、斜杠、星号、问号、双引号、尖括号和竖线字符。
    // python: value = re.sub(r'[\\/:*?"<>|]', "", value)
    func replaceInvalidCharacters() -> String {
        
        var value = self
        
        let arr = ["*", "/", "\\", "“", "”", "?", "<", ">", "|", ":", "？", "！"]
        
        for ca in arr {
            value = value.replacingOccurrences(of: ca, with: "")
        }
        
        return value
        
//        let pattern = "[\\\\/:*?\"<>|]" // 注意在 Swift 字符串中，你需要转义反斜杠和其他特殊字符
//        let regex = try! NSRegularExpression(pattern: pattern, options: [])
//        let modifiedString = regex.stringByReplacingMatches(in: value, options: NSRegularExpression.MatchingOptions.anchored, range: .init(location: 0, length: value.count), withTemplate: "")
//        return modifiedString as String
    }
}
